#ifndef SHOWCAMERA_H
#define SHOWCAMERA_H

#include <QWidget>
#include <QImage>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>    // 需要使用到3.3版本的QOpenGLFunctions
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>

#include <QThread>
#include <QTimer>

class showcamera : public QOpenGLWidget,protected QOpenGLFunctions_3_3_Core // 修改继承为QOpenGLFunctions_3_3_Core
{
    Q_OBJECT
public:
    explicit showcamera(QWidget *parent = nullptr);
    void setCameraData(const char* data, int width, int height);
    void setDetections(const std::vector<QRectF>& detections); // 增加检测框设置接口

protected:
    virtual void initializeGL() override;
    virtual void paintGL() override;
    virtual void resizeGL(int w, int h) override;


private:
    QWidget * QOpenGLWidget;

    // 核心渲染对象
    QOpenGLShaderProgram shaderProgram;
    QOpenGLVertexArrayObject VAO;
    QOpenGLBuffer VBO;
    QOpenGLTexture texture;

    // 检测框渲染对象
    QOpenGLBuffer detectionVBO;
    QOpenGLShaderProgram detectionShader;

    // 状态跟踪
    QSize lastImageSize;
    bool textureInitialized = false;
    bool detectionsInitialized = false;

    // 检测框数据
    std::vector<QRectF> currentDetections; // 当前检测框位置信息
    int detectionVertexCount = 0;           // 检测框顶点数量
};

#endif // SHOWCAMERA_H
